﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.HTML
{
    #region Using Statements

    using System;

    #endregion

    /// <summary>
    /// Embedded image. See the IMG element definition in HTML 4.01.
    /// </summary>
    public class HTMLImageElement : HTMLBlockBaseElement
    {
        #region Constructors

        internal HTMLImageElement(Document owner)
            : base(owner, HTMLConstants.HTML_TAG_IMG)
        {
        }

        #endregion

        #region DOM Level 2 HTML Compliance

        /// <summary>
        /// Alternate text for user agents not rendering the normal content of
        /// this element. See the alt attribute definition in HTML 4.01.
        /// </summary>
        public string alt
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_ALT);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_ALT);
                else
                    setAttribute(HTMLConstants.HTML_ATT_ALT, value);
            }
        }

        /// <summary>
        /// Width of border around image. See the border attribute definition
        /// in HTML 4.01. This attribute is deprecated in HTML 4.01. Note that
        /// the type of this attribute was DOMString in DOM Level 1 HTML 
        /// [DOM Level 1].
        /// </summary>
        public string border
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_BORDER);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_BORDER);
                else
                    setAttribute(HTMLConstants.HTML_ATT_BORDER, value);
            }
        }

        /// <summary>
        /// Height of the image in pixels. See the height attribute definition
        /// in HTML 4.01. Note that the type of this attribute was DOMString 
        /// in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int height
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_HEIGHT, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_HEIGHT, value);
            }
        }

        /// <summary>
        /// Horizontal space to the left and right of this image in pixels. 
        /// See the hspace attribute definition in HTML 4.01. This attribute 
        /// is deprecated in HTML 4.01. Note that the type of this attribute 
        /// was DOMString in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int hspace
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_HSPACE, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_HSPACE, value);
            }
        }

        /// <summary>
        /// Use server-side image map. See the ismap attribute 
        /// definition in HTML 4.01.
        /// </summary>
        public bool isMap
        {
            get
            {
                return getAttributeAsType<bool>(HTMLConstants.HTML_ATT_ISMAP, false);
            }
            set
            {
                setAttributeAsType<bool>(HTMLConstants.HTML_ATT_ISMAP, value);
            }
        }

        /// <summary>
        /// URI [IETF RFC 2396] designating a long description of this image 
        /// or frame. See the longdesc attribute definition in HTML 4.01.
        /// </summary>
        public string longDesc
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_LONGDESC);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_LONGDESC);
                else
                    setAttribute(HTMLConstants.HTML_ATT_LONGDESC, value);
            }
        }

        /// <summary>
        /// The name of the element (for backwards compatibility).
        /// </summary>
        public string name
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_NAME);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_NAME);
                else
                    setAttribute(HTMLConstants.HTML_ATT_NAME, value);
            }
        }

        /// <summary>
        /// URI [IETF RFC 2396] designating the source of this image. See the
        /// src attribute definition in HTML 4.01.
        /// </summary>
        public string src
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_SRC);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_SRC, value);
            }
        }

        /// <summary>
        /// Use client-side image map. See the usemap attribute definition
        /// in HTML 4.01.
        /// </summary>
        public string useMap
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_USEMAP);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_USEMAP);
                else
                    setAttribute(HTMLConstants.HTML_ATT_USEMAP, value);
            }
        }

        /// <summary>
        /// Vertical space above and below this image in pixels. See the 
        /// vspace attribute definition in HTML 4.01. This attribute is 
        /// deprecated in HTML 4.01. Note that the type of this attribute 
        /// was "DOMString" in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int vspace
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_VSPACE, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_VSPACE, value);
            }
        }

        /// <summary>
        /// The width of the image in pixels. See the width attribute 
        /// definition in HTML 4.01. Note that the type of this attribute 
        /// was DOMString in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int width
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_WIDTH, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_WIDTH, value);
            }
        }

        #endregion
    }
}
